package com.fufufu.mail.product.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.fufufu.mail.product.entity.CategoryEntity;
import com.fufufu.mail.product.service.CategoryService;
import com.fufufu.common.utils.PageUtils;
import com.fufufu.common.utils.R;



/**
 * 商品三级分类
 *
 * @author zyx
 * @email 1262074394@qq.com
 * @date 2022-09-15 08:15:48
 */
@RestController
@RequestMapping("product/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    /**
     * 三级分类查询
     */
    @RequestMapping("/list/tree")
    public R list(){
        List<CategoryEntity> categoryEntitys = categoryService.listWithTree();
        return R.ok().put("data", categoryEntitys);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{catId}")
    // @RequiresPermissions("product:category:info")
    public R info(@PathVariable("catId") Long catId){
		CategoryEntity category = categoryService.getById(catId);
        // 返回的数据同意用data标识
        return R.ok().put("data", category);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    // @RequiresPermissions("product:category:save")
    public R save(@RequestBody CategoryEntity category){
		categoryService.save(category);

        return R.ok();
    }

    /**
     * 批量修改
     */
    @RequestMapping("/updateList")
    public R updateList(@RequestBody CategoryEntity[] category){
        categoryService.updateBatchById(Arrays.asList(category));
        return R.ok();
    }
    /**
     * 修改
     */
    @RequestMapping("/update")
    // @RequiresPermissions("product:category:update")
    public R update(@RequestBody CategoryEntity category){
		categoryService.updateDetail(category);
        return R.ok();
    }

    /**
     * 删除
     * @RequestBody获取请求体里的内容(json)变成参数
     */
    @RequestMapping("/delete")
    // @RequiresPermissions("product:category:delete")
    public R delete(@RequestBody Long[] catIds){
        // 检测当前菜单是否被别的地方引用
//		categoryService.removeByIds(Arrays.asList(catIds));
        categoryService.removemenueByIds(Arrays.asList(catIds));
        return R.ok();
    }

}
